


/*   sq
                you(10)  31-34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19                auto(6) 11-15
20                
21
22
23
24
25                
26                mini(4) 0-9
27
28
29
30 -
31       - *                 *                 *                *
32 auto
33       you
34 -     -                   *                  *                *
35================  ======================
                 +  +
               ========
*/

/*   
    you:  31.9 ~ 36.9
    auto: 11.9 ~ 16.9  19.9
    mini:  0 ~ 6
*/



class ScottMath {
    constructor(){}

    lineLength(line) { // 返回线段长度
        return Math.sqrt((line.xe - line.xs) ** 2 + (line.ye - line.ys) ** 2)
    }
    p2p(p1, p2) { // 点到点距离 输入 {x: y:}, {x: y:}
        return Math.sqrt( (p2.x-p1.x)**2 + (p2.y-p1.y)**2 )
    }
    angleToPi(angle) { // 角度转pi 如 输入 180 输出 3.1415...
        return Math.PI / 180 * angle
    }
    
    
    lineLengthAdd(line, length) { // 线段长度向两端增减 返回增减后的线段 length 是单端增减长度
        if (line.xe - line.xs == 0 || line.ye - line.ys == 0) {
            if (line.xe - line.xs == 0 ) {
                return {
                    xs: line.xs,
                    ys: line.ys + (line.ye - line.ys > 0 ? -length : length),
                    xe: line.xe,
                    ye: line.ye + (line.ye - line.ys > 0 ? length : -length)
                }
            } else {
                return {
                    xs: line.xs - (line.xe - line.xs > 0 ? length : -length),
                    ys: line.ys,
                    xe: line.xe - (line.xe - line.xs > 0 ? -length : length),
                    ye: line.ye
                }
            }
        }
        let lineLength =  this.lineLength(line)
        let k = length / lineLength;
        let x = line.xe - line.xs;
        let y = line.ye - line.ys;
        return {
            xs: line.xs - k * x,
            ys: line.ys - k * y,
            xe: line.xe + k * x,
            ye: line.ye + k * y
        }
    }
    lineLengthScale(line, scale) { // 线段长度缩放 返回缩放后的线段
        let length = this.lineLength(line)
        return this.lineLengthAdd( line , (length * scale - length) / 2) 
    }
    vectorMove(line, len) { // 返回线段起点向终点移动len距离后的坐标
        let {xs, ys, xe, ye} = line
        if(xs == xe) {
            ys = ys + (ye > ys? len : -len)
        } else if (ys == ye) {
            xs = xs + (xe > xs? len : -len)
        } else {
            let allLen = this.p2p({x:xs, y:ys} , {x:xe,y:ye} )
            let k = len/allLen;
            xs = (xe-xs) * k + xs
            ys = (ye-ys) * k + ys
        }
        return {x:xs, y:ys}
    }
    rodataLine(line, angle) { // 线段 顺时针旋转角度 
        angle = -this.angleToPi(angle)
        var sin = Math.sin(angle);
        if (Math.abs(angle - Math.atan2(0, -1)) < 0.0000001) { sin = 0 };
        var cos = Math.cos(angle);
        if (Math.abs(angle - Math.atan2(1, 0)) < 0.0000001) { cos = 0 };
        var x = (line.xe - line.xs) * cos - (line.ye - line.ys) * sin + (line.xs - 0);
        var y = (line.xe - line.xs) * sin + (line.ye - line.ys) * cos + (line.ys - 0);
        return {xs: line.xs, ys: line.ys, xe: x, ye: y}
    }
    translateLine(line, len) { // 线段向右平移 平移距离 len
        var line_tmp = {}
        var lineLength = Math.sqrt((line.xe - line.xs)*(line.xe - line.xs) + (line.ye - line.ys)*(line.ye - line.ys))
        line_tmp.xe = line.xe - (len / lineLength) * (line.ys - line.ye)
        line_tmp.ye = line.ye - (len / lineLength) * (line.xe - line.xs)
        line_tmp.xs = line.xs - (len / lineLength) * (line.ys - line.ye)
        line_tmp.ys = line.ys - (len / lineLength) * (line.xe - line.xs)
        return line_tmp
    }

    // 碰撞检测类
    getltl(line1, line2) { // 返回 两线段交点 或者false 
        let a = {
            x: line1.xs, y: line1.ys,
        }, b = {
            x: line1.xe, y: line1.ye,
        }, c = {
            x: line2.xs, y: line2.ys,
        }, d = {
            x: line2.xe, y: line2.ye,
        };
        let denominator = (b.y - a.y) * (d.x - c.x) - (a.x - b.x) * (c.y - d.y);
        if (denominator === 0) {
            return false; // 两线段平行或者共线
        }
        let x = ((b.x - a.x) * (d.x - c.x) * (c.y - a.y)
            + (b.y - a.y) * (d.x - c.x) * a.x
            - (d.y - c.y) * (b.x - a.x) * c.x) / denominator;
        let y = -((b.y - a.y) * (d.y - c.y) * (c.x - a.x)
            + (b.x - a.x) * (d.y - c.y) * a.y
            - (d.x - c.x) * (b.y - a.y) * c.y) / denominator;
        if (
            (x - a.x) * (x - b.x) <= 0 && (y - a.y) * (y - b.y) <= 0
            && (x - c.x) * (x - d.x) <= 0 && (y - c.y) * (y - d.y) <= 0
        ) {
            return { x, y }
        }
        return false
    }
    pointTouchLimits(p, limit) { // 点在范围内
        let {xmin, xmax, ymin, ymax} = limit
        if(p.x >= xmin && p.x <= xmax && p.y >= ymin && p.y <= ymax) {
            return true
        }
    }
    pointTouchRect(p, rect) { // 点在rect内
        let {x, y, width, height} = rect
        let xOffset = Math.abs(x - p.x);
        let yOffset = Math.abs(y - p.y);
        if(xOffset <= width/2 && yOffset <= height) {
            return true
        }
    }
    rectTouchRect(rect1, rect2) { // 矩形touch
        let rectsWidth = (rect1.width + rect2.width)/2;
        let rectsHeight = (rect1.height + rect2.height)/2;
        let xOffset = Math.abs(rect2.x - rect1.x);
        let yOffset = Math.abs(rect2.y - rect1.y);
        if(xOffset <= rectsWidth && yOffset <= rectsHeight) {
            return true
        }
    }
    rectTouchLimits(rect, limit) {  // 无角度矩形在 limit范围内 非精确
        let {x, y, width, height} = rect
        let xc = limit.xmin + (limit.xmax-limit.xmin) / 2
        let yc = limit.ymin + (limit.ymax-limit.ymin) / 2
        let xsize = Math.abs(limit.xmax-limit.xmin)
        let ysize = Math.abs(limit.ymax-limit.ymin)
        return this.rectTouchRect(rect, {x:xc, y:yc, width:xsize, height:ysize})
    }
}

let math = new ScottMath();


// you:   s: 31-34
// auto:  s: 11-15
// mini:  s: 0-9

// 31.9-45.9

//       v



// y 

// (l/r)/(2**0.5)*90

// 0 0 0 0 0 0 0 0 


let you = {
    title: "you",
    range: [11.9, 45.9],
    pRange: [31.9, 45.9],
}

let auto = {
    title: "auto",
    range: [8.9, 32.9],
    pRange: [11.9, 23.9],
}

let mini = {
    title: "mini",
    range: [0, 28.9],
    pRange: [0, 14.45],
}


let youPao = [];
let youPaoS = [];
let jiange = 6

//  sq
for (let index = -50; index < 50; index++) {
    youPaoS.push({x: index * jiange, y: 0})
}
let fs = require("fs")
//  round
let roundR = 44
let line = {xs:0, ys:roundR, xe:roundR, ye:roundR}
let angleTmp = 0
for (let index = 0; index < 1000; index++) {
    let angle = Math.asin(jiange/(roundR*2))/Math.PI * 180 * 2;
    angleTmp += angle
    if (angleTmp >= 360) {
        break
    }
    let l2 = math.rodataLine(line, angle)
    line = l2
    youPao.push({x: l2.xe, y: l2.ye})
}

console.log(youPao.length);

// let arr = [you, auto, mini]
let arr = [auto]
let data_R = []
let data_S = []
arr.forEach(pao => {
    let {title, range, pRange} = pao;
    for (let index = -range[0]; index > -range[1]; index--) {
    
        let enemy = { x: 0, y: index }
        let activeCount = 0;
        youPao.forEach(v => {
            let length = p2p(v, enemy);
            if (length <= pRange[1] && length >= pRange[0]) {
                activeCount++
            }
        });
        data_R.push(`${title}  len:${index} count:${activeCount}`)
    }

    for (let index = -range[0]; index > -range[1]; index--) {
    
        let enemy = { x: 0, y: index }
        let activeCount = 0;
        youPaoS.forEach(v => {
            let length = p2p(v, enemy);
            if (length <= pRange[1] && length >= pRange[0]) {
                activeCount++
            }
        });
        data_S.push(`${title}  len:${index} count:${activeCount}`)
    }
});
fs.writeFileSync("./paoR.js", data_R.join("\n"))
fs.writeFileSync("./paoS.js", data_S.join("\n"))



function p2p(p1, p2) {
    return Math.sqrt((p2.x-p1.x)**2 + (p2.y-p1.y)**2)
}





function addPao(maxRange, minPowerRange, maxPowerRange, x, y) {
	GEN.addPad({x:x, y:y, symbol:"donut_r"+(maxRange*200+10)+"x"+(maxRange*200-10)});

	GEN.addPad({x:x, y:y, symbol:"donut_r"+maxPowerRange*200+"x"+minPowerRange*200,polarity:"negative"});

	GEN.addPad({x:x, y:y, symbol:"donut_r"+(maxPowerRange*200+30)+"x"+((maxPowerRange*200-30)<0? 0:(maxPowerRange*200-30))});
	GEN.addPad({x:x, y:y, symbol:"donut_r"+(minPowerRange*200+30)+"x"+((minPowerRange*200-30)<0? 0:(minPowerRange*200-30))});

	GEN.addPad({x:x,y:y, symbol:"r300"})
}



/*



["objectName","modal","windowModality","enabled","geometry","frameGeometry","normalGeometry","x","y","pos",
"frameSize","size","width","height","rect","childrenRect","childrenRegion","sizePolicy","minimumSize","maximumSize",
"minimumWidth","minimumHeight","maximumWidth","maximumHeight","sizeIncrement","baseSize","palette","font","cursor",
"mouseTracking","isActiveWindow","focusPolicy","focus","contextMenuPolicy","updatesEnabled","visible","minimized","maximized",
"fullScreen","sizeHint","minimumSizeHint","acceptDrops","windowTitle","windowIcon","windowIconText","windowOpacity","windowModified",
"toolTip","toolTipDuration","statusTip","whatsThis","accessibleName","accessibleDescription","layoutDirection","autoFillBackground",
"styleSheet","locale","windowFilePath","inputMethodHints","frameShape","frameShadow","lineWidth","midLineWidth","frameWidth",
"frameRect","verticalScrollBarPolicy","horizontalScrollBarPolicy","sizeAdjustPolicy","autoScroll","autoScrollMargin","editTriggers",
"tabKeyNavigation","showDropIndicator","dragEnabled","dragDropOverwriteMode","dragDropMode","defaultDropAction","alternatingRowColors",
"selectionMode","selectionBehavior","iconSize","textElideMode","verticalScrollMode","horizontalScrollMode","showGrid","gridStyle",
"sortingEnabled","wordWrap","cornerButtonEnabled","dragMode","_q_styleSheetWidgetFont","destroyed(QObject*)","destroyed()","objectNameChanged(QString)",
"deleteLater()","windowTitleChanged(QString)","windowIconChanged(QIcon)","windowIconTextChanged(QString)","customContextMenuRequested(QPoint)",
"setEnabled(bool)","setDisabled(bool)","setWindowModified(bool)","setWindowTitle(QString)","setStyleSheet(QString)","setFocus()","update()","repaint()",
"setVisible(bool)","setHidden(bool)","show()","hide()","showMinimized()","showMaximized()","showFullScreen()","showNormal()","close()","raise()","lower()",
"updateMicroFocus()","grab(QRect)","grab()","pressed(QModelIndex)","clicked(QModelIndex)","doubleClicked(QModelIndex)","activated(QModelIndex)",
"entered(QModelIndex)","viewportEntered()","iconSizeChanged(QSize)","reset()","setRootIndex(QModelIndex)","doItemsLayout()","selectAll()",
"edit(QModelIndex)","clearSelection()","setCurrentIndex(QModelIndex)","scrollToTop()","scrollToBottom()","update(QModelIndex)",
"dataChanged(QModelIndex,QModelIndex,QVector<int>)","dataChanged(QModelIndex,QModelIndex)","rowsInserted(QModelIndex,int,int)",
"rowsAboutToBeRemoved(QModelIndex,int,int)","selectionChanged(QItemSelection,QItemSelection)","currentChanged(QModelIndex,QModelIndex)",
"updateEditorData()","updateEditorGeometries()","updateGeometries()","verticalScrollbarAction(int)","horizontalScrollbarAction(int)",
"verticalScrollbarValueChanged(int)","horizontalScrollbarValueChanged(int)","closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)",
"commitData(QWidget*)","editorDestroyed(QObject*)","selectRow(int)","selectColumn(int)","hideRow(int)","hideColumn(int)","showRow(int)",
"showColumn(int)","resizeRowToContents(int)","resizeRowsToContents()","resizeColumnToContents(int)","resizeColumnsToContents()",
"sortByColumn(int)","setShowGrid(bool)","rowMoved(int,int,int)","columnMoved(int,int,int)","rowResized(int,int,int)","columnResized(int,int,int)",
"rowCountChanged(int,int)","columnCountChanged(int,int)","indexWidgetCommit(QWidget*,QModelIndex)","dataChanged()","rowsInserted()",
"rowsMoved()","rowsRemoved()","rowCheckStateChanged(QModelIndex)","anyDataChanged()","notification(QString,QVariant,QString)",
"notification(QString,QVariant)","notification(QString)","sortHeaderTable()","sortIndicatorChanged(int,int)","setData(QString,QVariant)",
"getData(QString,QVariant)","getData(QString)","getData()","setHeaderItem(QVariantList)","headerItem()","initialHeaderItem()",
"setRowResizeToContents()","setColumnState(int,QVariantMap,bool)","setColumnState(int,QVariantMap)","setColumnVisible(QString,bool)",
"setColumnVisible(int,bool)","setColumnVisible(QMap<QString,bool>)","isColumnVisible(QString)","isColumnVisible(int)","columnName(int)",
"colummNumber(QString)","isColumnVisible(QStringList)","isColumnVisible()","setRowVisible(QModelIndex,bool)","refreshRowVisible()",
"selectedIndexes()","appendRow(QVariant)","prependRow(QVariant)","appendRows(QVariantList)","prependRows(QVariantList)","appendRowNR(QVariant)",
"prependRowNR(QVariant)","appendRowsNR(QVariantList)","prependRowsNR(QVariantList)","addRowBefore(QVariant,QModelIndex)","addRowBefore(QVariant)",
"addRowAfter(QVariant,QModelIndex)","addRowAfter(QVariant)","addRowsBefore(QVariantList,QModelIndex)","addRowsBefore(QVariantList)",
"addRowsAfter(QVariantList,QModelIndex)","addRowsAfter(QVariantList)","addRowBefore(QVariant,QVariant,QString)","addRowBefore(QVariant,QVariant)",
"addRowAfter(QVariant,QVariant,QString)","addRowAfter(QVariant,QVariant)","addRowsBefore(QVariantList,QVariant,QString)",
"addRowsBefore(QVariantList,QVariant)","addRowsAfter(QVariantList,QVariant,QString)","addRowsAfter(QVariantList,QVariant)",
"addRowBeforeSelectedRows(QVariant)","addRowAfterSelectedRows(QVariant)","addRowsBeforeSelectedRows(QVariantList)","addRowsAfterSelectedRows(QVariantList)",
"setRowKeyValue(QModelIndex,QString,QVariant)","setRowData(QModelIndex,QVariant,bool)","setRowData(QModelIndex,QVariant)",
"setRowKeyValueByPrimaryKey(QVariant,QString,QVariant)","setRowDataByPrimaryKey(QVariant,QVariant,bool)","setRowDataByPrimaryKey(QVariant,QVariant)",
"removeRow(QModelIndex)","removeRows(QModelIndexList)","removeSelectedRows()","moveRowsUp(QModelIndexList)","moveSelectedRowsUp()",
"moveRowsDown(QModelIndexList)","moveSelectedRowsDown()","moveRowsTop(QModelIndexList)","moveSelectedRowsTop()","moveRowsBottom(QModelIndexList)",
"moveSelectedRowsBottom()","selectRow(QVariant,QItemSelectionModel::SelectionFlags)","selectRow(QVariant)",
"selectRow(QModelIndex,QItemSelectionModel::SelectionFlags)","selectRow(QModelIndex)","selectRows(QVariantList,QItemSelectionModel::SelectionFlags)",
"selectRows(QVariantList)","selectRows(QModelIndexList,QItemSelectionModel::SelectionFlags)","selectRows(QModelIndexList)","unselectAll()",
"selectRowNR(QVariant)","selectRowsNR(QVariantList)","loadData(QVariantList)","clearData()","findRow(QVariant,QString)","findRow(QVariant)",
"findRows(QVariant,QString,int)","findRows(QVariant,QString)","findRows(QVariant)","findRows(QVariantList,QString,int)","findRows(QVariantList,QString)",
"findRows(QVariantList)","findRows(QRegExp,QStringList,int)","findRows(QRegExp,QStringList)","findRows(QRegExp)","findRowsNR(QVariant,QString,int)",
"findRowsNR(QVariant,QString)","findRowsNR(QVariant)","findRowsNR(QVariantList,QString,int)","findRowsNR(QVariantList,QString)","findRowsNR(QVariantList)",
"findRowsNR(QRegExp,QStringList,int)","findRowsNR(QRegExp,QStringList)","findRowsNR(QRegExp)","setContextMenu(QMenu*)","contextMenu()",
"showContextMenu(QPoint)","gridLineMode()","setGridLineMode(int)","showHeaderPopup(QPoint)","headerPopup()","setHeaderPopupEnabled(bool)",
"setHeaderSortingEnabled(bool)","setHeaderSortingEnabled()","saveState()","restorSaveState(QString)","setModel(QAbstractItemModel*)",
"dragMode()","setDragMode(int)","allDataMap(QString,QString,bool)","allDataMap(QString,QString)","allDataMap(QString)","allDataMap()",
"selectedRowDataMaps(bool)","selectedRowDataMaps()","setPrimaryKey(QString)","allPrimaryKey(bool)","allPrimaryKey()","dataKeyList()",
"setDataKeyList(QStringList)","setVisibleKey(QString)","selectedPrimaryKeys(bool)","selectedPrimaryKeys()","currentRowDataMap()","currentRowDataList()",
"currentPrimaryKey()","rowDataMap(QString)","adjustViewSpan(QVariantList,QStringList,int,int,int)","adjustViewSpan(QStringList)","onDoTableViewSort()"]


*/